#pragma once
#include<iostream>
#include<string>
#include<unistd.h>

using namespace std;

const int defaultvalue = 0;
const string opers = "+-*/%)(|";

enum
{
    ok = 0,
    div_zero,
    mod_zero,
    unkown
};

class Task
{
public:
    Task()
    {}
    
    Task(int x, int y, char op)
        :data_x(x)
        ,data_y(y)
        ,oper(op)
        ,result(defaultvalue)
        ,code(ok)
    {}

    void Run()
    {
        switch(oper)
        {
        case'+':
            result = data_x + data_y;
            break;
        case'-':
            result = data_x - data_y;
            break;
        case'*':
            result = data_x * data_y;
            break;
        case'/':
          {
            if(data_y == 0)
                code = div_zero;
            else
                result = data_x / data_y;
          }
        break;
        case'%':
          {
            if(data_y == 0)
                code = mod_zero;
            else
                result = data_x % data_y;
          }
        break;
        default:
            code = unkown;
            break;
        }
    }

    void operator()()
    {
        Run();
        sleep(2);
    }

    string PrintTask()
    {
        string s;
        s = to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += "=?";

        return s;
    }

    string PrintResult()
    {
        string s;
        s = to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += "=";
        s += to_string(result);
        s += "[";
        s += to_string(code);
        s += "]";

        return s;
    }

    ~Task()
    {}
private:
    int data_x;
    int data_y;
    char oper;  //+-/*%
    int result;
    int code;  /* 结果码 0: 可信, !0 不可信 */
};